unit Class_DEPT;

interface
uses
  Classes,SysUtils,ADODB,DBEngineEx;

type
  TDEPT=class(TDbEngine)
  public
    UNITLINK: string;
    DEPTLINK: string;
    DEPTCODE: string;
    DEPTNAME: string;
    DEPTKIND: string;
    NAMELINK: string;
    DEPTLEVL: Integer;
    DEPTPREV: string;
    DEPTCALL: string;
    DEPTMEMO: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AADOConnection:TADOConnection):Integer;overload;
  public
    function  CheckExist(AADOConnection:TADOConnection):Boolean;override;
  public
    class function  ReadDS(AADODataSet:TADODataSet):TDbEngine;override;
    class function  CopyIt(ADEPT:TDEPT):TDEPT;overload;        
    class procedure CopyIt(ADEPT:TDEPT;var Result:TDEPT);overload;       
  end;

implementation

{ TDEPT }
procedure TDEPT.SetParameters;
begin
  inherited;
  with FADOCmd.Parameters do
  begin
    case FOpType of
      otAdd:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
        ParamByName('DEPT_CODE').Value := DEPTCODE;
        ParamByName('DEPT_NAME').Value := DEPTNAME;
        ParamByName('DEPT_KIND').Value := DEPTKIND;
        ParamByName('NAME_LINK').Value := NAMELINK;
        ParamByName('DEPT_LEVL').Value := DEPTLEVL;
        ParamByName('DEPT_PREV').Value := DEPTPREV;
        ParamByName('DEPT_CALL').Value := DEPTCALL;
        ParamByName('DEPT_MEMO').Value := DEPTMEMO; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
        ParamByName('DEPT_CODE').Value := DEPTCODE;
        ParamByName('DEPT_NAME').Value := DEPTNAME;
        ParamByName('DEPT_KIND').Value := DEPTKIND;
        ParamByName('NAME_LINK').Value := NAMELINK;
        ParamByName('DEPT_LEVL').Value := DEPTLEVL;
        ParamByName('DEPT_PREV').Value := DEPTPREV;
        ParamByName('DEPT_CALL').Value := DEPTCALL;
        ParamByName('DEPT_MEMO').Value := DEPTMEMO; 
      end;  
      otDel:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
 
      end;  
    end;
  end;
end;

function TDEPT.CheckExist(AADOConnection: TADOConnection): Boolean;
begin
  Result:=CheckExist('TBL_DEPT',['UNIT_LINK',UNITLINK,'DEPT_LINK',DEPTLINK],AADOConnection);
end;

function TDEPT.GetNextIdex: Integer;
begin

end;

function TDEPT.GetNextIdex(AADOConnection: TADOConnection): Integer;
begin

end;

function TDEPT.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_DEPT WHERE   UNIT_LINK=:UNIT_LINK AND DEPT_LINK=:DEPT_LINK';
end;

function TDEPT.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_DEPT'
         +'    ( UNIT_LINK, DEPT_LINK, DEPT_CODE, DEPT_NAME, DEPT_KIND'
         +'    , NAME_LINK, DEPT_LEVL, DEPT_PREV, DEPT_CALL, DEPT_MEMO)'
         +'    VALUES'
         +'    (:UNIT_LINK,:DEPT_LINK,:DEPT_CODE,:DEPT_NAME,:DEPT_KIND'
         +'    ,:NAME_LINK,:DEPT_LEVL,:DEPT_PREV,:DEPT_CALL,:DEPT_MEMO)';
end;

function TDEPT.GetStrsIndex: string;
begin
  Result:=Format('%S-%S',[UnitLink,DeptLink]);
end;

function TDEPT.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_DEPT SET'
         +'    DEPT_CODE=:DEPT_CODE,'
         +'    DEPT_NAME=:DEPT_NAME,'
         +'    DEPT_KIND=:DEPT_KIND,'
         +'    NAME_LINK=:NAME_LINK,'
         +'    DEPT_LEVL=:DEPT_LEVL,'
         +'    DEPT_PREV=:DEPT_PREV,'
         +'    DEPT_CALL=:DEPT_CALL,'
         +'    DEPT_MEMO=:DEPT_MEMO'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   DEPT_LINK=:DEPT_LINK';
end;

class function TDEPT.ReadDS(AADODataSet: TADODataSet): TDbEngine;
begin
  Result:=TDEPT.Create;
  with TDEPT(Result) do
  begin
    UNITLINK:=AADODataSet.FieldByName('UNIT_LINK').AsString;
    DEPTLINK:=AADODataSet.FieldByName('DEPT_LINK').AsString;
    DEPTCODE:=AADODataSet.FieldByName('DEPT_CODE').AsString;
    DEPTNAME:=AADODataSet.FieldByName('DEPT_NAME').AsString;
    DEPTKIND:=AADODataSet.FieldByName('DEPT_KIND').AsString;
    NAMELINK:=AADODataSet.FieldByName('NAME_LINK').AsString;
    DEPTLEVL:=AADODataSet.FieldByName('DEPT_LEVL').AsInteger;
    DEPTPREV:=AADODataSet.FieldByName('DEPT_PREV').AsString;
    DEPTCALL:=AADODataSet.FieldByName('DEPT_CALL').AsString;
    DEPTMEMO:=AADODataSet.FieldByName('DEPT_MEMO').AsString;
  end;  
end;

class function  TDEPT.CopyIt(ADEPT: TDEPT): TDEPT;
begin
  Result:=TDEPT.Create;
  Result.UNITLINK:=ADEPT.UNITLINK;
  Result.DEPTLINK:=ADEPT.DEPTLINK;
  Result.DEPTCODE:=ADEPT.DEPTCODE;
  Result.DEPTNAME:=ADEPT.DEPTNAME;
  Result.DEPTKIND:=ADEPT.DEPTKIND;
  Result.NAMELINK:=ADEPT.NAMELINK;
  Result.DEPTLEVL:=ADEPT.DEPTLEVL;
  Result.DEPTPREV:=ADEPT.DEPTPREV;
  Result.DEPTCALL:=ADEPT.DEPTCALL;
  Result.DEPTMEMO:=ADEPT.DEPTMEMO;
end;

class procedure TDEPT.CopyIt(ADEPT:TDEPT;var Result:TDEPT);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=ADEPT.UNITLINK;
  Result.DEPTLINK:=ADEPT.DEPTLINK;
  Result.DEPTCODE:=ADEPT.DEPTCODE;
  Result.DEPTNAME:=ADEPT.DEPTNAME;
  Result.DEPTKIND:=ADEPT.DEPTKIND;
  Result.NAMELINK:=ADEPT.NAMELINK;
  Result.DEPTLEVL:=ADEPT.DEPTLEVL;
  Result.DEPTPREV:=ADEPT.DEPTPREV;
  Result.DEPTCALL:=ADEPT.DEPTCALL;
  Result.DEPTMEMO:=ADEPT.DEPTMEMO;
end;

end.

